﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Raise3000.Code.Foundation;

namespace Raise3000.Code.Attribute_Calculator
{
    // Formula : Total times bet F|T|R / Total times bet F|T|R + Total times checked F|T|R

    class Attr_BetCalculator : ICalculator
    {
        Dictionary<string, long> betOnTheFlop_ = new Dictionary<string, long>();
        Dictionary<string, long> betOnTheTurn_ = new Dictionary<string, long>();
        Dictionary<string, long> betOnTheRiver_ = new Dictionary<string, long>();

        Dictionary<string, long> checkOnTheFlop_ = new Dictionary<string, long>();
        Dictionary<string, long> checkOnTheTurn_ = new Dictionary<string, long>();
        Dictionary<string, long> checkOnTheRiver_ = new Dictionary<string, long>();

        public Attr_BetCalculator()
        {
        }

        public override void DispatchAction(PlayerAction action, HandContextHelper hcHelper)
        {
            if (!hcHelper.IsPreflop() && !hcHelper.IsThereBetBehind())
            {
                bool doesBet = action.Move == ActionEnum.eBET;

                StreetEnum currentStreet = hcHelper.GetCurrentStreet();
                switch (currentStreet)
                {
                    case StreetEnum.eFLOP:
                        {
                            if (doesBet)
                            {
                                betOnTheFlop_[action.PlayerName]++;
                            }
                            else
                            {
                                checkOnTheFlop_[action.PlayerName]++;
                            }
                            break;
                        }
                    case StreetEnum.eTURN:
                        {
                            if (doesBet)
                            {
                                betOnTheTurn_[action.PlayerName]++;
                            }
                            else
                            {
                                checkOnTheTurn_[action.PlayerName]++;
                            }
                            break;
                        }
                    case StreetEnum.eRIVER:
                        {
                            if (doesBet)
                            {
                                betOnTheRiver_[action.PlayerName]++;
                            }
                            else
                            {
                                checkOnTheRiver_[action.PlayerName]++;
                            }
                            break;
                        };
                    default:
                        {
                            // how the fuck do we get here?
                            throw new Exception();
                        }
                };
            }
        }

        public override void RegisterPlayer(string playerTemplateName)
        {
            if (!betOnTheFlop_.ContainsKey(playerTemplateName))
            {
                betOnTheFlop_.Add(playerTemplateName, 0);
                betOnTheTurn_.Add(playerTemplateName, 0);
                betOnTheRiver_.Add(playerTemplateName, 0);

                checkOnTheFlop_.Add(playerTemplateName, 0);
                checkOnTheTurn_.Add(playerTemplateName, 0);
                checkOnTheRiver_.Add(playerTemplateName, 0);
            }
        }

        public override void OnStartHand(HandContextHelper hcHelper)
        {
            // nothing to do
        }

        public override void OnEndHand(HandContextHelper hcHelper)
        {
            // nothing to do
        }

        public override StatisticalAttribute CreateStatisticalAttribute(string player)
        {
            return new StatisticalAttribute("Bet", 0);
        }
    }
}
